package com.adinall.dsp.core.globle;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.adinall.dsp.core.data.KeyValueTitleBean;
import com.adinall.dsp.core.utils.DateUtils;

/**
 * 选择器
 * 
 * @author 高万超
 * @version V1.0.0 $ 2017年9月20日 上午10:59:57
 */
public final class Selector {

    /**
     * 日期选择器
     * 
     * @return List 选择器列表
     */
    public static List<KeyValueTitleBean<String, String>> date() {

        List<KeyValueTitleBean<String, String>> data = new ArrayList<>();

        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -1);

        String yesterday = DateUtils.format(c.getTime(), DateUtils.PATTERN_yyyy_MM_dd);

        // 昨天
        data.add(new KeyValueTitleBean<String, String>(yesterday, yesterday, "昨天"));

        // 前七天
        c.add(Calendar.DAY_OF_MONTH, -6);
        data.add(new KeyValueTitleBean<String, String>(DateUtils.format(c.getTime(), DateUtils.PATTERN_yyyy_MM_dd), yesterday, "前七天"));

        // 上周
        String lastWeekMonday = DateUtils.format(DateUtils.monday(-1).getTime(), DateUtils.PATTERN_yyyy_MM_dd);
        String lastWeekSunday = DateUtils.format(DateUtils.sunday(-1).getTime(), DateUtils.PATTERN_yyyy_MM_dd);
        data.add(new KeyValueTitleBean<String, String>(lastWeekMonday, lastWeekSunday, "上周"));

        // 本月
        c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH, 1);
        String thisMonthFirstDay = DateUtils.format(c.getTime(), DateUtils.PATTERN_yyyy_MM_dd);
        data.add(new KeyValueTitleBean<String, String>(thisMonthFirstDay, yesterday, "本月"));

        // 上月
        c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        c.set(Calendar.DAY_OF_MONTH, 1);
        String lastMonthFirstDay = DateUtils.format(c.getTime(), DateUtils.PATTERN_yyyy_MM_dd);

        c.set(Calendar.DAY_OF_MONTH, DateUtils.day(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1));
        String lastMonthLastDay = DateUtils.format(c.getTime(), DateUtils.PATTERN_yyyy_MM_dd);
        data.add(new KeyValueTitleBean<String, String>(lastMonthFirstDay, lastMonthLastDay, "上月"));

        return data;
    }
}
